JavaScript Replace all

replaceAll() returns a new string with every occurrence of the search value replaced. It is the natural fix for replace()’s "first match only" behaviour, without needing a global regex.

Syntax

str.replaceAll(search, replacement)

Examples

Input Arguments Output
"a-b-c" "-", "+" "a+b+c"

Gotchas

  • With a regex argument the /g flag is mandatory, or it throws.

Try it live

Type your input and see Replace all transform it instantly.

Description: Replaces all occurrences of a substring with another.

Example: 'chocolate chip cookie chocolate'.replaceAll('chocolate', 'vanilla') => 'vanilla chip cookie vanilla'

Want to go further? Chain Replace all with other functions in the visual Playground — pipe one output into the next and watch your data transform.

Related functions

© 2026 Heifara Buval